<?php
class ControllerCommonSeoUrl extends Controller {
	public function index() {
		if (isset($this->request->get['_route_'])) {
			
			$parts = explode('/', $this->request->get['_route_']);
			
			foreach ($parts as $part) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE keyword = '" . $this->db->escape($part) . "'");
				
				if ($query->num_rows) {
					
					$url = explode('&', $query->row['query']);
					
					foreach ($url as $k=>$v){
						
						$u = explode('=',$v);
						if ($u[0] == 'product_id') {
							$this->request->get['product_id'] = $u[1];
							
						}
						if ($u[0] == 'article_id') {
							$this->request->get['article_id'] = $u[1];
							
						}
						
						if ($u[0] == 'category_id') {
							if (!isset($this->request->get['path'])) {
								$this->request->get['path'] = $u[1];
							} else {
								$this->request->get['path'] .= '_' . $u[1];
							}
						}	
						if ($u[0] == 'cat_id') {
							if (!isset($this->request->get['paths'])) {
								$this->request->get['paths'] = $u[1];
							} else {
								$this->request->get['paths'] .= '_' . $u[1];
							}
						}
						
						if ($u[0] == 'manufacturer_id') {
							$this->request->get['manufacturer_id'] = $u[1];
						}
						
						if ($u[0] == 'information_id') {
							$this->request->get['information_id'] = $u[1];
						}							
					}
				
				} else {
					$this->request->get['route'] = 'error/not_found';	
				}
			}
			
			if (isset($this->request->get['product_id'])) {
				$this->request->get['route'] = 'product/product';
			}elseif (isset($this->request->get['article_id'])) {
				$this->request->get['route'] = 'product/article';
			} elseif (isset($this->request->get['paths'])) {
				$this->request->get['route'] = 'product/cat';
			}elseif (isset($this->request->get['path'])) {
				$this->request->get['route'] = 'product/category';
			} elseif (isset($this->request->get['manufacturer_id'])) {
				$this->request->get['route'] = 'product/manufacturer';
			} elseif (isset($this->request->get['information_id'])) {
				$this->request->get['route'] = 'information/information';
			}
			
			if (isset($this->request->get['route'])) {
				return $this->forward($this->request->get['route']);
			}
		}
	}
}
?>